pacman::p_load(tidyverse, readxl, naniar, marginaleffects, modelsummary)
raw_df <- read_xlsx("Data/Data.xlsx")
df <- raw_df %>%
replace_with_na(replace = list(Q15.1 = c(88, 99),
Q15.2 = c(88, 99),
Q16.1 = c(88, 99),
Q16.2 = c(88, 99),
Q2.1 = 99,
Q2.3 = 99,
Q2.4 = 99,
Q3_1 = 99,
Q4.1 = 99,
Q7.1 = 99,
Q13.1 = c(6, 99))) %>%
mutate(Q15.1 = 6 - Q15.1,
Q15.2 = recode(Q15.2,
"1" = "5",
"2" = "4",
"3" = "2",
"4" = "1",
"5" = "3"),
Q16.1 = 6 - Q16.1,
Q16.2 = recode(Q16.2,
"1" = "5",
"2" = "4",
"3" = "2",
"4" = "1",
"5" = "3"),
Female = sex - 1,
Age = age,
Educ = Q2.1,
Income = Q2.3,
Urban = 5 - Q2.4,
Duty = Q3_1,
Interest = 5 - Q4.1,
Independent = if_else(Q7.1 == 11, 1, 0),
Voted = if_else(Q13.1 <= 3, 1, 0)) %>%
rename(Treatment = votingrate) %>%
filter(Q3_8 == 4)
df2 <- df %>%
group_by(Treatment) %>%
summarise(Outcome = mean(Q16.1, na.rm = TRUE),
.groups = "drop")